const express = require('express');
const expressjwt = require('express-jwt');
// 导入数据库连接
const mysql = require('./conn');
// 实例化express对象
const app = express();
const cors= require('cors');
app.use(cors());
// 解析body数据 中间件
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());

const upload = require('./routes/upload');
app.use('/upload',upload);

const product = require('./routes/product');
app.use('/product',product);

// 将image文件转换成静态资源
// app.use('/image',express.static('./image'));
app.use(express.static('image'));
mysql.connect((err)=>{
    if(err){
       return console.log('数据库连接失败',err)
    }
    console.log('数据库连接成功！');
});

// 定义端口号
const port = 5000;

app.listen(port,()=>{
    console.log(`服务器运行http://localhost:${port}`)
})